from enum import Enum

class DeezerTrackQuality(Enum):
  AAC_64 = 1
  MP3_64 = 2
  MP3_128 = 3
  MP3_256 = 4
  MP3_320 = 5
  FLAC = 6
  @staticmethod
  def from_raw_data(raw_data):
    bindings = {
      "FILESIZE_AAC_64": "AAC_64",
      "FILESIZE_MP3_64": "MP3_64",
      "FILESIZE_MP3_128": "MP3_128",
      "FILESIZE_MP3_256": "MP3_256",
      "FILESIZE_MP3_320": "MP3_320",
      "FILESIZE_FLAC": "FLAC"
    }
    track_qualities = list(map(
      lambda k: bindings[k],
      filter(
        lambda k: k in bindings and raw_data[k] != 0 and raw_data[k] != "0",
        raw_data.keys(),
      )
    ))
    return track_qualities
  @staticmethod
  def get_file_format(quality):
    if isinstance(quality, DeezerTrackQuality):
      quality = quality.name
    formats = {
      ".aac": ['AAC_64'],
      ".mp3": ['MP3_64', 'MP3_128', 'MP3_256', 'MP3_320'],
      ".flac": ['FLAC']
    }
    for format in formats.keys():
      qualities = formats[format]
      if quality in qualities:
        return format
